﻿Public Enum UserEventTypes
    normal = 0
    important
End Enum

<ContentType(label:="Event", list_label:="Events")>
Public Class UserEvent
    Inherits BaseContent

    <ReferenceText(), ContentProperty()>
    Public Property title As ContentPropertyValue(Of String) = ""

    <ContentProperty(label:="date")>
    Public Property event_date As ContentPropertyValue(Of Date) = Date.Now

    <ContentReference()>
    Public Property content As New SingleContentReference(Of IContent)

    ''' <summary>
    ''' do not use this, use event_type to be more confortable with enums
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    <ContentProperty()>
    Public Property event_type_int As ContentPropertyValue(Of Integer) = 0

    Public Property event_type As UserEventTypes
        Get
            Return Me.event_type_int.value
        End Get
        Set(value As UserEventTypes)
            Me.event_type_int.value = value
        End Set
    End Property

    Public Class Comparer
        Implements IComparer(Of UserEvent)

        Public Function Compare(x As UserEvent, y As UserEvent) As Integer Implements System.Collections.Generic.IComparer(Of UserEvent).Compare
            'recent first
            Return -Date.Compare(x.event_date.value, y.event_date.value)
        End Function
    End Class


    Public Shared Function getAllNormalEvents() As IEnumerable(Of UserEvent)
        Dim cd As IContentDispatcher = MysteryExtensions.getGlobalObject(Of IContentDispatcher)(Nothing)
        Dim result As IEnumerable(Of UserEvent) = cd.getAllByFilter(Of UserEvent)(New UserEvent With {.event_type_int = New ContentPropertyFilter(Of Integer)(0)})
        Return result
    End Function

End Class